home *** CD-ROM | disk | FTP | other *** search
/ The World's Largest Collection of Windows Software / The World's Largest Collection of Windows Software - Disc 1.iso / connect / _j2 / wsmtpd16 / wsmtpsrv.h < prev    next >
C/C++ Source or Header  |  1993-10-09  |  8KB  |  222 lines

  1. /* WSMTPSrv.C - Windows SMTP Server V1.40a
  2.     - WinSock 1.1 required
  3.  
  4.    * Handles multiple clients at one time for reliable and quick
  5.      mail service.
  6.  
  7.    * Uses the Windows Sockets API for wide useability.
  8.  
  9.    Author: Ian Blenke
  10.    Date:   May 23, 1993
  11.  
  12.    v1.30a   June 24, 1993    8BITMIME capable.
  13.    v1.40a   June 28, 1993    Unlimited connection capability.
  14.                              Cleaner code. Linked lists.
  15.                              More bugs destroyed.
  16. */
  17.  
  18. #ifndef WSMTPSRV_H
  19. #define WSMTPSRV_H
  20.  
  21. #include <Windows.h>
  22. #include <CommDlg.h>
  23. #include <Stdarg.h>
  24. #include "WinSock.h"
  25. #include "Ctl3d.h"
  26. #include "Dialogs.h"
  27. #include "Net.h"
  28.  
  29. #define USE_3D          /**/// Uncomment this for 3d Dialog feel
  30. /*#define USE_TITLE     /**/// Uncomment this for Dialog title
  31.                             // bytes sent/received debugging
  32.  
  33. #define APP_NAME        "WSMTPSRV"
  34. #define CLASS_NETWORK   "SMTPClass"
  35. #define WSVERSION       0x101
  36. #define DEFAULTMAILFILE "c:\\mail.txt"
  37. #define MAXLINE         128
  38. #define MAXFILENAME     144
  39. #define MAXSNDBUFF      2048  // I don't think this app will EVER need
  40.                               // this much of a Sending buffer.
  41. #define MAXITEMS        1000  // Limit the listbox size
  42. #define MAXCLIENTS      10    // Up this number if you need more
  43. #define INI_FILE        "wsmtpsrv.ini"
  44.  
  45. #define TIME_CHECK      30000 // 30000ms==30 seconds
  46. #define ID_TIMER        2600  // Misc. timer handle  ;)
  47.  
  48.     // Miscellanous String Defines
  49. #define STRING_PREFIX   "WSMTP"
  50. #define STRING_UNKNOWN  "Unknown System"
  51. #define STRING_NOMAIL   "WSMTPD v1.61"
  52. #define STRING_HAVEMAIL "WSMTPD v1.61 - Mail!"
  53. #define SECTION_MAIN    "WinSMTPSrv"
  54. #define ENTRY_DEBUG     "Debug"
  55. #define ENTRY_MAILPATH  "Mail"
  56.  
  57.     // A server connection can be in 2 "states"
  58. #define STATE_WAIT_FOR_COMMAND      0
  59. #define STATE_WAIT_FOR_DOT          1
  60.  
  61.     // Extended SMTP flag values
  62. #define ESMTP_NONE      0
  63. #define ESMTP_EHLO_USED 1
  64. #define ESMTP_8BITMIME  2
  65. #define ESMTP_SIZE      4
  66.  
  67.     // Level of reporting
  68. #define LOG_LOW         0
  69. #define LOG_MEDIUM      1
  70. #define LOG_HIGH        2
  71.  
  72. #define LOG_TIME        8   // Use Time with the log entry
  73.  
  74. /* SMTP Command structure - For easy parsing */
  75. typedef struct
  76. {
  77.  PSTR SMTPCommand;
  78.  WORD SMTPCode;             // Tokens for this field are in "Dialogs.h"
  79. } SMTPCODE;
  80.  
  81. /* Odd hack to keep "phase" debug strings static */
  82. typedef const PSTR PHASESTRING;
  83.  
  84. /* For Vanities sake                             */
  85. typedef HANDLE HCLIENT;
  86.  
  87.  
  88. /* Client structure for multiple connections          */
  89. /* All state flags/variables should be stored in here */
  90. typedef struct tagSMTPCLIENT
  91. {
  92.  SOCKET sSocket;            // Socket handle of the connection
  93.  HCLIENT hClient;           // Handle to "this" client link
  94.  
  95.  SOCKADDR_IN saPeer;        // Peer name
  96.  char szPeer[MAXLINE];      // Room for the peer name
  97.  
  98.  HFILE hfFile;              // Handle for the open .TMP file
  99.  char szFile[MAXFILENAME];  // .TMP filename per message
  100.  char szFrom[MAXLINE];      // Room for the Sender's ID
  101.  char szTo[MAXLINE];        // Room for the Recipient's ID
  102.  BOOL bHaveFrom;            // Only let id sender once/message
  103.  int iMessageType;          // MAIL/SEND/SAML/SOML?
  104.  BOOL iState;               // SMTP State (2 states, 0 and 1)
  105.  int iExtendedFlags;        // ESMTP flags
  106.  
  107.      /* We need buffers to talk with - unique ones at that */
  108.  HANDLE hOutputBuffer;      // Handle to output FIFO buffer
  109.  LPSTR lpOutputBuffer;      // FIFO buffer for output
  110.  int fifoOutputStart;       // Start of buffer where valid
  111.  int fifoOutputStop;        // End of buffer where valid
  112.  int iInputSize;            // Size of FIFO buffer for input
  113.  HANDLE hInputBuffer;       // Handle to input FIFO buffer
  114.  LPSTR lpInputBuffer;       // FIFO buffer for input
  115.  int fifoInputStart;        // Start of buffer where valid
  116.  int fifoInputStop;         // End of buffer where valid
  117.  
  118.  struct tagSMTPCLIENT FAR *lpPrevClient; // Link to previous client struct
  119.  struct tagSMTPCLIENT FAR *lpNextClient; // Link to next client struct
  120. } SMTPCLIENT;
  121.  
  122. /* estimated size per structure:
  123.   2+2+4+128+2+144+128+128+2+2+2+2+2+4+2+2+2+2+4+2+2+4+4 == 578 bytes/client
  124.   Not including the separate buffers for each FIFO!
  125.  
  126.   Know the real bummer? As long as the socket remains open, the memory used
  127.   for the buffers remain locked. Lets just hope noone makes a client that
  128.   doesn't close connection and repetively re-connects. Can you say "Your
  129.   Doctor Watson log is getting quite large"?
  130. */
  131.  
  132. typedef SMTPCLIENT FAR *LPSMTPCLIENT;
  133.  
  134.             /* GLOBALS */
  135. LPSMTPCLIENT smtpClientsHead; // Head of Client's linked list
  136.  
  137. /* Clients array for future multiple clients at a time support */
  138.  
  139. /* The SMTP Command Code lookup table */
  140. /* Just keep adding in those new ones */
  141. static SMTPCODE smtpCodesTable[] =
  142. {
  143.     {"helo",     CMDHELO},    /* helo -- be polite */
  144.     {"ehlo",     CMDEHLO},    /* ehlo -- extended SMTP */
  145.     {"verb",     CMDVERB},    /* onex -- sending one transaction only */
  146.     {"onex",     CMDONEX},    /* verb -- go into verbose mode */
  147.     {"mult",     CMDMULT},    /* mult -- multiple message query */
  148.     {"mail",     CMDMAIL},    /* mail -- designate sender */
  149.     {"rcpt",     CMDRCPT},    /* rcpt -- designate recipient */
  150.     {"data",     CMDDATA},    /* data -- send message text */
  151.     {"rset",     CMDRSET},    /* rset -- reset state */
  152.     {"vrfy",     CMDVRFY},    /* vrfy -- verify address */
  153.     {"expn",     CMDVRFY},    /* expn -- verify address */
  154.     {"help",     CMDHELP},    /* help -- give usage info */
  155.     {"noop",     CMDNOOP},    /* noop -- do nothing     */
  156.     {"quit",     CMDQUIT},    /* quit -- close connection and die */
  157.     {"tick",     CMDTICK},    /* tick -- batch SMTP sync command */
  158.     {"turn",     CMDTURN},    /* turn -- switch places */
  159.     {"send",     CMDSEND},    /* send -- send message to screen */
  160.     {"saml",     CMDSAML},    /* saml -- send AND mail  */
  161.     {"soml",     CMDSOML},    /* soml -- send OR mail   */
  162.     /*
  163.      * Implementation specific extensions.
  164.      */
  165.     {"xwin3",    CMDXWIN3},   /* xwin3 -- tell me you are a Win3 client */
  166.     /*
  167.      * remaining commands are here only
  168.      * to trap and log attempts to use them
  169.      * And to laugh at the poor soul who does.
  170.      */
  171.     {"showq",    CMDDBGQSHOW},/* showq -- show send queue */
  172.     {"debug",    CMDDBGDEBUG},/* debug -- set debug mode */
  173.     {(PSTR)NULL, CMDERROR}    /* bad command */
  174. };
  175.  
  176. #ifndef NET_C
  177. HINSTANCE hInst;
  178. int iLogLevel = LOG_LOW;
  179. extern BOOL bMailArrived;
  180. BOOL bConnectionQuit;
  181. #else
  182. BOOL bMailArrived = FALSE;  // Icon Flag!
  183. extern int iLogLevel;
  184. extern HINSTANCE hInst;
  185. #endif // NET_C
  186.  
  187.         /* The main Dialog globals */
  188. char szLocalHostName[MAXLINE];
  189. OPENFILENAME ofnMailPath;
  190. static char szMailPathFilter[MAXLINE];
  191. static char szLocalMailPath[MAXFILENAME];
  192. char szAppName[40];
  193. int iMaxSndBuf;             // Maximum send buffer size
  194. int iMaxRcvBuf;             // Maximum receive buffer size
  195. HWND hWndDlg;               // Main dialog window
  196. HWND hWndMain;              // Main "network" window
  197.  
  198.     /* PROTOTYPES */
  199. UINT PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
  200. LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
  201. LRESULT CALLBACK IconWndProc(HWND, UINT, WPARAM, LPARAM);
  202. LRESULT CALLBACK AboutProc(HWND, UINT, WPARAM, LPARAM);
  203. void smtpError(int, ...);
  204. void smtpLog(int, ...);
  205. BOOL smtpInit(PSTR);
  206. BOOL smtpServer(LPSMTPCLIENT);
  207. BOOL smtpParser(LPSMTPCLIENT, int, LPSTR);
  208. LPSMTPCLIENT smtpSocketToClient(SOCKET);
  209. void smtpAppendToFile(LPSMTPCLIENT, LPSTR, LPSTR);
  210. BOOL smtpDisplayFile(LPSMTPCLIENT, LPSTR);
  211. LPSTR smtpSkipWord(LPSMTPCLIENT, LPSTR, LPSTR);
  212. void smtpSendHelp(LPSMTPCLIENT, LPSTR);
  213. void smtpMakeHeader(LPSMTPCLIENT, HFILE, LPSTR, LPSTR, LPSTR);
  214. LPSMTPCLIENT smtpAddClient(SOCKET);
  215. BOOL smtpDestroyClient(LPSMTPCLIENT);
  216. BOOL smtpMailCheck(LPSTR);
  217. void smtpSendMessage(LPSMTPCLIENT, int, int, ...);
  218. int  clientSendLine(LPSMTPCLIENT, LPSTR, int);
  219. int  clientReceiveLine(LPSMTPCLIENT, LPSTR, int);
  220. int  clientReceiveBlock(LPSMTPCLIENT, LPSTR, int);
  221. #endif /* WSMTPSRV_H */
  222.